/*
 * Copyright (c) 2017. Visionet and/or its affiliates. All right reserved.
 * VISIONET PROPRIETARY/CONFIDENTIAL.
 */
package com.visionet.jumper.project.sample.controller.security;

import com.visionet.jumper.core.domain.bean.Page;
import com.visionet.jumper.utils.JsonUtils;
import com.visionet.security.base.enums.ResourceType;
import com.visionet.security.domain.dto.UrlizedResource;
import com.visionet.security.domain.entity.Resource;
import com.visionet.security.service.SecurityResourceService;
import com.visionet.security.support.ResourceHelper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author TC.Ubuntu
 * @since 2017/7/11.
 */
@Controller
@RequestMapping("/security")
public class SecurityResourceController {

	@javax.annotation.Resource
	private SecurityResourceService securityResourceService;

	@RequestMapping("/resource/index")
	public String resourceIndex() {
		return "system/resource";
	}

	@RequestMapping(value = "/resource", method = RequestMethod.POST)
	public String resourceAdd(Resource resource) {
		resource.setType(ResourceType.MENU);
		securityResourceService.save(resource);
		return "system/resource";
	}

	@RequestMapping(value = "/userMenu", method = RequestMethod.GET)
	@ResponseBody
	public List<UrlizedResource> getUserMenu() {
		return ResourceHelper.getUserMenu();
	}

	@RequestMapping(value = "/resource", method = RequestMethod.GET)
	@ResponseBody
	public Page getResource(Page page) {
		return ResourceHelper.getMenuForPage(page);
	}
}
